using System.Linq;
using System;

namespace PersonalAccoutingProgram.Data
{
    partial class IncomeViewDataClassesDataContext
    {
        public static IQueryable<decimal> GetIncomesForDay(
            DateTime date, string username)
        {
            IncomeViewDataClassesDataContext incomesDC =
            new IncomeViewDataClassesDataContext();
            var allIncomesForDate =
            from currentIncome in incomesDC.GetTable<IncomesView>()
            where currentIncome.IncomesDate == date &&
                  currentIncome.Username == username
            select currentIncome.IncomesAmount;
            return allIncomesForDate;
        }

        public static IQueryable<decimal> GetIncomesForDayByCategory(
            DateTime date, string username, string category)
        {
            IncomeViewDataClassesDataContext incomesDC =
            new IncomeViewDataClassesDataContext();
            var allIncomesForDate =
            from currentIncome in incomesDC.GetTable<IncomesView>()
            where currentIncome.IncomesDate == date &&
                  currentIncome.Username == username &&
                  category == currentIncome.OriginName
            select currentIncome.IncomesAmount;
            return allIncomesForDate;
        }

        public static IQueryable<decimal> GetIncomesForMonth(
            string username, DateTime dateForCheck)
        {
            IncomeDataClassesDataContext incomesDC =
            new IncomeDataClassesDataContext();
            var allIncomesForUser =
            from currentIncome in incomesDC.GetTable<IncomesView>()
            where currentIncome.Username == username && 
                  currentIncome.IncomesDate.Year == dateForCheck.Year && 
                  currentIncome.IncomesDate.Month == dateForCheck.Month
            select currentIncome.IncomesAmount;
            return allIncomesForUser;
        }

        public static IQueryable<decimal> GetUserIncomesForMonthByorigin(
            string username, string category, DateTime dateForCheck)
        {
            IncomeViewDataClassesDataContext incomesDC = 
            new IncomeViewDataClassesDataContext();
            var allIncomesForUser =
            from currentIncome in incomesDC.GetTable<IncomesView>()
            where currentIncome.Username == username &&
                  category == currentIncome.OriginName && 
                  currentIncome.IncomesDate.Year == dateForCheck.Year &&
                  currentIncome.IncomesDate.Month == dateForCheck.Month
            select currentIncome.IncomesAmount;
            return allIncomesForUser;
        }

        public static IQueryable<decimal> GetIncomesForYear(string username, DateTime dateForCheck)
        {
            IncomeViewDataClassesDataContext incomesDC =
            new IncomeViewDataClassesDataContext();
            var allIncomesForUser =
            from currentIncomes in incomesDC.GetTable<IncomesView>()
            where currentIncomes.Username == username &&
                  currentIncomes.IncomesDate.Year == dateForCheck.Year
            select currentIncomes.IncomesAmount;
            return allIncomesForUser;
        }

        public static IQueryable<decimal> GetIncomesForYearByCategory(string username, string category, DateTime dateForCheck)
        {
            IncomeViewDataClassesDataContext incomesDC =
            new IncomeViewDataClassesDataContext();
            var allIncomesForUser =
            from currentIncomes in incomesDC.GetTable<IncomesView>()
            where currentIncomes.Username == username &&
                  currentIncomes.IncomesDate.Year == dateForCheck.Year &&
                  currentIncomes.OriginName == category
            select currentIncomes.IncomesAmount;
            return allIncomesForUser;
        }

        public static IQueryable<IncomesView> GetAllUserIncomes(string username)
        {
            IncomeViewDataClassesDataContext incomesDC =
            new IncomeViewDataClassesDataContext();
            var allIncomesForUser =
            from currentIncomes in incomesDC.GetTable<IncomesView>()
            where currentIncomes.Username == username
            select currentIncomes;
            return allIncomesForUser;
        }

        public static IQueryable<IncomesView> GetAllUserIncomesByCategory(
            string username, string category)
        {
            IncomeViewDataClassesDataContext incomesDC =
            new IncomeViewDataClassesDataContext();
            var allIncomesForUser =
            from currentIncomes in incomesDC.GetTable<IncomesView>()
            where currentIncomes.Username == username &&
                  currentIncomes.OriginName == category
            select currentIncomes;
            return allIncomesForUser;
        }
    }
}